﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
   public  class MonHocDAO
    {
        public static bool KiemTraMaMonHoc(string maMonHoc)
        {
            return TraCuuMonHoc(maMonHoc);
        }

        public static bool KiemTraMonHoc(string tenMonHoc)
        {
            string command = "select * from MonHoc where MonHoc.tenMonHoc = N'" + tenMonHoc + "'";
            DataTable tb = new DataTable();

            try
            {
                tb = DaTaProvider.excecuteQuery(command);
            }
            catch (Exception ex)
            {
                return false;
            }
            if (tb.Rows.Count == 0)
                return false;

            return true;
         }

        public static DataTable LayDuLieuFullMonHoc()
        {
            
            string command = "select * from MonHoc";
            DataTable tb = new DataTable();
            try
            {
                tb = DaTaProvider.excecuteQuery(command);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            int ic = tb.Columns.Count;

            tb.Columns[0].ColumnName = "Mã Môn Học";
            tb.Columns[1].ColumnName = "Tên Môn Học";

            return tb;

        } 

        public static DataTable LayDuLieuMonHoc()
        {
            string command = "select MonHoc.tenMonHoc from MonHoc";
            DataTable tb = new DataTable();
            try
            {
                tb = DaTaProvider.excecuteQuery(command);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return tb;

        }

        public static bool TraCuuMonHoc(string maMonHoc)
        {
            string command = "select * from MonHoc where MonHoc.maMonHoc = '" + maMonHoc + "'" ;
            DataTable tb = new DataTable();
            try
            {
                tb = DaTaProvider.excecuteQuery(command);
            }
            catch (Exception ex)
            {
                return false;
            }
            if (tb.Rows.Count == 0)
                return false;
            return true;
        }

       public static bool ThemMonHoc( string tenMonHoc, string maMonHoc )
       {
           string command = "insert into MonHoc( maMonHoc, tenMonHoc )"
           +  " values( '" + maMonHoc + "', N'" + tenMonHoc + "' )";

           int flag = 0;
           try
           {

              flag =  DaTaProvider.ExcecuteNonQuery(command);
           }
           catch (Exception ex)
           {
               return false;
           }
           return true;
       }

       public static bool XoaMonHoc(string tenMonHoc)
       {
           string command = "delete MonHoc"
              + " where MonHoc.tenMonHoc = N'" + tenMonHoc + "'";

           try
           {
               DaTaProvider.ExcecuteNonQuery(command);
           }
           catch (Exception ex)
           {
               return false;
           }

           return true;
       }
    }
}
